<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>用户管理</title>
		<link href="<%=application.getContextPath()%>/nresources/ued/css/all-src.css" type="text/css" rel="stylesheet" />
		<%@include file="/WEB-INF/ibnms/common/easyui.jsp" %>
		<%@include file="/WEB-INF/ibnms/common/jqgrid.jsp"%>
		<%@ include file="/WEB-INF/ibnms/common/jsCommonVariables.jsp"%>
	</head>
<body>
<div class="form-wrapper">
	<div class="block02">
        <div class="title-style02">
			<input type="button" class="btn-style02" id="btn-add" value="增加">&nbsp;&nbsp;
			<input type="button" class="btn-style02" id="btn-edit" value="修改">&nbsp;&nbsp;
			<input type="button" class="btn-style02" id="btn-del" value="删除">
		</div>
	
		<table id="gridTable">
		</table>
		<div id="gridPager">
		</div>
		<form name="theForm" >
		</form>
	</div>
</div>
<script type="text/javascript">
			$(function(){$("#gridTable").jqGrid({
					url: "loadListSysParaQueryJson.do",
					datatype: "json",
					mtype: "POST",
					height: "100%",
					autowidth: true,
					colNames:['参数ID', '参数名称', '参数值', '参数描述', '是否有效'],
					colModel:[
						{name:'PARA_ID',index:'PARA_ID'},
						{name:'PARA_NAME',index:'PARA_NAME'},
						{name:'PARA_VALUE',index:'PARA_VALUE'},
						{name:'PARA_DESC',index:'PARA_DESC'},
						{name:'ENABLE',index:'ENABLE',formatter: function(value){
							if (value=="1"){
								return "是";
							} else {
								return "否";
							}
						}}
					],
					viewrecords: true,
					rowNum: 15,
					rowList: [10,15,30],
					jsonReader: {
						root: 'rows',
						page: 'page',
						total: 'total',
						records: 'records',
						repeatitems: false,
						subgrid: {
					        root: 'rows',
							page: 'page',
							total: 'total',
							records: 'records',
							repeatitems: false
					    }      
					},
					pager: "#gridPager",
					hidegrid: true,
					multiselect: true
				});
				
			}); 
			
			
			$("#btn-add").click(function(){
				$("form[name='theForm']").append("<input type='hidden' name='theForm.ISMP_JSP_COMMAND' value='add'/>");
				$("form[name='theForm']").attr("action","<s:url action='editSysPara' namespace='/'/>").submit();
			});
			$("#btn-del").click(function(){
			 	var idArr = jQuery("#gridTable").jqGrid('getGridParam','selarrrow');
                if (idArr.length == 0) {
                    alert("请先选择要删除的记录!");
                    return;
                }
				if(confirm("是否删除所选的记录?")){
					var para_id = "";
                    for (var one in idArr){
                    	var data = jQuery("#gridTable").jqGrid('getRowData',idArr[one]);
                    	para_id += data.PARA_ID + ",";
                    }
                    if(para_id.length>0){
                    	para_id = para_id.substring(0,para_id.length-1);
                    }
					$.ajax({
						type: "POST",
						async: false,
						url: "<s:url action="delSysPara" namespace='/'/>?theForm.PARA_ID="+para_id,
						success: function(data){
	                        if (data != "true"){
								alert(data);
	                        }else{
	                       		$("#gridTable").trigger('reloadGrid');
	                       		alert("删除成功");
	                       	}
						},
						error:function(xhr){  
							show_error(xhr);
						}
					});	
                }
			});
			$("#btn-edit").click(function() {
				var idArr = jQuery("#gridTable").jqGrid('getGridParam','selarrrow');
				switch (idArr.length) {
					case 0:
						alert("请先选择要修改的记录!");
						break;
					case 1:
						var data = jQuery("#gridTable").jqGrid('getRowData',idArr[0]);
						var para_id = data.PARA_ID;
						$("form[name='theForm']").append("<input type='hidden' name='theForm.ISMP_JSP_COMMAND' value='update'/>");
						$("form[name='theForm']").append("<input type='hidden' name='theForm.PARA_ID' value='"+para_id+"'/>");
						$("form[name='theForm']").attr("action","<s:url action='editSysPara' namespace='/'/>");
						$("form[name='theForm']").submit();
						break;
					default:
						alert("一次只能修改一条记录!");
				}
			}); 
		</script>
</body>
</html:html>            
